package com.sc.es.service.house;

import com.sc.es.common.HouseResult;
import com.sc.es.entity.HouseTag;
import com.sc.es.repo.HouseTagRepo;
import com.sc.es.service.IHouseService;
import com.sc.es.service.IHouseTagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author sc
 * Created on  2018/2/8
 */
@Service
public class HouseTagService implements IHouseTagService {
    @Autowired
    private HouseTagRepo tagRepo;

    @Override
    public HouseResult deleteTag(Integer houseId, String tag) {
        HouseTag houseTag = tagRepo.findByHouseIdAndName(houseId,tag);
        if(houseTag==null){
            return HouseResult.notFound();
        }
        tagRepo.delete(houseTag.getId());
        return HouseResult.success();
    }

    @Override
    public HouseResult addTag(Integer houseId, String tag) {
        HouseTag houseTag = new HouseTag();
        houseTag.setName(tag);
        houseTag.setHouseId(houseId);
        tagRepo.save(houseTag);
        return HouseResult.success();
    }
}
